﻿namespace Mvc3App.Domain.Entities
{
    public abstract class BaseEntity
    {
        public virtual int Id { get; set; }

        public override bool Equals(object obj)
        {
            var other = obj as BaseEntity;

            if (other == null)
            {
                return false;
            }

            if (this.Id.Equals(default(int)) && other.Id.Equals(default(int)))
            {
                return this == other;
            }

            return this.Id.Equals(other.Id);
        }

        public override int GetHashCode()
        {
            if (this.Id.Equals(default(int)))
            {
                return base.GetHashCode();
            }

            var stringRepresentation = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName + "#" + this.Id;

            return stringRepresentation.GetHashCode();
        }
    }
}